feat: recover from repeated crashes by going into safe mode - #7
Open
mateoalfaro wants to merge 2 commits into
Open
feat: recover from repeated crashes by going into safe mode#7mateoalfaro wants to merge 2 commits into
mateoalfaro wants to merge 2 commits into
Conversation
run_safe_mode() forced the software rendering stack (GSK_RENDERER=cairo, WLR_RENDERER=pixman, llvmpipe). On machines with a working GPU the recovery session then renders the entire desktop on the CPU, maxing out cores and making the session unusably slow (observed: libinput event lag, glamor fallback in labwc.log) — the opposite of what a recovery mode should do. In the escalation ladder the software path has already failed by the time safe mode starts, so forcing it there cannot help either. Safe mode now runs the default rendering stack. Operators who suspect the GPU stack itself can opt back in with SINGULARITY_SAFE_MODE_SOFTWARE=1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Today the session scripts only know one recovery trick: if the compositor dies
early, retry with software rendering once. If the shell crashes, the session
just restarts it forever, and a genuine crash loop (e.g. an assertion failure
in labwc, or a bad shell update) produces an endless restart cycle with no way
for the user to get to a working desktop or fix their settings.
This adds a crash-loop detection layer to the session that escalates to
Safe Mode (see the companion
singularity-shellPR): after repeatedfailures the session relaunches in a recovery configuration with a persisted
marker, and leaves safe mode automatically once the binaries change.
singularity-labwc-sessionsession, and desktop binaries (
SINGULARITY_SESSION_BUILD_IDoverrides itfor tests). Markers and requests are scoped to it.
retry (existing behavior, preserved) → write a Safe Mode marker → safe-mode
attempt. Non-zero exits that are neither crashes nor short-lived (130/143,
≥30s runtime) don't trigger recovery.
software stack (
GSK_RENDERER=cairo,WLR_RENDERER=pixman, llvmpipe) madethe recovery session itself CPU-bound and unusably slow on machines with a
working GPU, and in the escalation ladder the software path has already
failed by the time safe mode starts. Operators who suspect the GPU stack
can opt back in with
SINGULARITY_SAFE_MODE_SOFTWARE=1.$XDG_STATE_HOME/singularity/safe-mode(versioned,records build id, reason, exit status, elapsed time, timestamp; written
atomically with 0600). A marker only applies to the same build id — after
an update the session tries normal mode again, so a fixed build can never be
trapped in recovery.
safe-mode-requestlets the shell supervisor(below) escalate; if the outer supervisor was killed before consuming it,
the next display-manager launch still honors it.
SINGULARITY_SAFE_MODE=1runs a safe session directly;SINGULARITY_FORCE_NORMAL=1bypasses an existing marker. Compositor binarypaths are overridable (
SINGULARITY_LABWC_BINARY, …) for testing/packaging.singularity-desktop-sessionsingularity-desktop) in a supervisor: clean exits restartimmediately; crashes restart with a 2s backoff. 3 crashes within a 5
minute window escalates: writes
safe-mode-request(with build id) andterminates the session so the outer script relaunches in safe mode.
SINGULARITY_SESSION_SUPERVISOR_ONLY=1provides a side-effect-free entrypoint for black-box testing (placed before all service/user mutations).
Testing
tests/session_safe_mode_test.sh(mesontest('session-safe-mode')):exercises the supervisor crash-window logic and the labwc-session marker /
build-id / escalation behavior end-to-end via the env-var entry points.
singularity-desktopthree times → session escalates to safemode and the shell's Safe Mode panel appears; clearing it via "Restart
Normal Session" returns to a normal session.
Related
singularity-shellchange implementing the recovery sessionitself (feature suppression + Settings repair surface).
Tested on NixOS 26.11